﻿using System.IO;
using System.Xml.Serialization;
using Loki.Game;

namespace toNyxPhysRanger
{
    [XmlRoot("AbilitySettings")]
    public class AbilitySettings
    {

        [XmlIgnore]
        private string _defaultSettingsPath = string.Format(Loki.Utilities.Xml.XmlSettings.SettingsDirectory + "\\toNyxPhysRangerSettings\\{0} - {1}\\",
            LokiPoe.ObjectManager.Me.League,
            LokiPoe.ObjectManager.Me.Name);

        [XmlElement("UseCriticalWeakness")] public bool UseCriticalWeakness;

        [XmlElement("UseRainOfArrows")] public bool UseRainOfArrows;

        [XmlElement("UseSplitArrow")] public bool UseSplitArrow;

        [XmlElement("AoETargetsAmount")] public int AoETargetsAmount;


        public void SaveAbilitiesData()
        {
            // Handling Namespaces
            var ns = new XmlSerializerNamespaces();
            ns.Add("", "");

            string path = _defaultSettingsPath + "AbilitySettings.xml";

            if (!Directory.Exists(_defaultSettingsPath))
                Directory.CreateDirectory(_defaultSettingsPath);

            var xs = new XmlSerializer(typeof(AbilitySettings));
            using (var sw = new StreamWriter(path.Replace(@"\\", @"\")))
            {
                xs.Serialize(sw, this, ns);
            }
        }

        public void GetAbilitiesData()
        {
            string path = _defaultSettingsPath + "AbilitySettings.xml";

            if (!File.Exists(path)) return;

            var xs = new XmlSerializer(typeof(AbilitySettings));
            using (var rd = new StreamReader(path))
            {
                var tempAbilitySettings = (AbilitySettings)xs.Deserialize(rd);

                // HOLY MOLLY DATA !!!
                UseCriticalWeakness = tempAbilitySettings.UseCriticalWeakness;
                UseRainOfArrows = tempAbilitySettings.UseRainOfArrows;
                UseSplitArrow = tempAbilitySettings.UseSplitArrow;
                AoETargetsAmount = tempAbilitySettings.AoETargetsAmount;
            }
        }


    }
}
